package com.xxl.job.executor.service.access.goods;

import com.web.all.common.bean.response.Result;
import com.xxl.job.core.biz.model.ReturnT;
import com.xxl.job.core.handler.IJobHandler;
import com.xxl.job.core.handler.annotation.JobHandler;
import com.xxl.job.core.log.XxlJobLogger;
import com.xxl.job.executor.mvc.api.GoodsAccessApi;
import com.xxl.job.executor.service.duty.PersonnelDutyTaskJobHandler;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;


/**
 * 物品准入证过期
 *
 * @author zhangchongyang
 */
@JobHandler(value = "GoodsAccessJobHandler")
@Component
public class GoodsAccessJobHandler extends IJobHandler {
    private static final Logger log = LoggerFactory.getLogger(GoodsAccessJobHandler.class);

    private final GoodsAccessApi goodsAccessApi;

    @Autowired
    public GoodsAccessJobHandler(GoodsAccessApi goodsAccessApi) {
        this.goodsAccessApi = goodsAccessApi;
    }

    @Override
    public ReturnT<String> execute(String param) throws Exception {
        XxlJobLogger.log("GoodsAccessJobHandler, 物品准入证过期.");
        log.info("GoodsAccessJobHandler, 物品准入证过期.");
        try {
            Result result = goodsAccessApi.synchronizedAccessStatus();
            if (result.isSuccess()) {
                XxlJobLogger.log("GoodsAccessJobHandler, 物品准入证过期成功.");
                log.info("GoodsAccessJobHandler, 物品准入证过期成功.");
                return SUCCESS;
            }
            XxlJobLogger.log("GoodsAccessJobHandler, 物品准入证过期失败.");
            log.error("GoodsAccessJobHandler, 物品准入证过期失败.原因：{}", result.getMsg());
            return FAIL;
        } catch (Exception e) {
            log.error("GoodsAccessJobHandler, 物品准入证过期失败. 原因：{}", e.getMessage());
            return FAIL;
        }
    }
}
